<template>
  <div class="chart3">
    <PublicEcharts
      v-if="!loadingFlag"
      :option="this.indexPersonData"
        :title="'人员概况'"
        :id="'indexPersonData'"
        :method="this.handlePersonClick"
    ></PublicEcharts>
    <div v-if="loadingFlag" class="e-loading">
      <dv-loading style="color: #fff">人员概况数据加载中...</dv-loading>
    </div>
  </div>
</template>

<script>
 
import { getPersonOption } from "../../utils/chartOption/indexChartOption";
import PublicEcharts from "../../components/charts/PublicEcharts";

export default {
  //import引入的组件需要注入到对象中才能使用
  components: { PublicEcharts },
  props: {},
  data() {
    //这里存放数据
    return {
      indexPersonData: null,
      loadingFlag: true,
    };
  },
  //计算属性 类似于data概念
  // computed: {
  //   areaCode() {
  //     return this.$store.state.listAreaIndex;
  //   },
  // },
  // //监控data中的数据变化
  // watch: {
  //   areaCode(newVal, oldVal) {
  //     console.log("区域code有改动 -- chart3: [" + newVal + "]");
  //     this.init();
  //   },
  // },
  //方法集合
  methods: {
    // 人员点击事件
    handlePersonClick (e) {
      console.log(e);
      // return 
      this.$store.commit('clearIndex')
      this.$store.commit("setListTypeIndex", e.dataIndex)
      this.$store.commit("setListTitle", '人员概况');
      this.$store.commit('setListCategory', 'postGetPersonInfoById')
      let params = {}
      this.$router.push({
        name: "list-page",
        params: params,
      });
    },
    init() {
      this.loadingFlag = true;
      let area_code = this.$store.getters.getAreaList[
        this.$store.getters.getListAreaIndex
      ]["area_code"];
      let params = { area_code };
      this.$http.postGetPersonInfo(params).then((e) => {
        let ret = e.data;
        if (ret.errorCode != 0) {
          console.log("后台运行异常!");
          return console.log(ret);
        }
        // console.log(ret.data);
        let arrs = {
          types: [],
          data: [],
        };
        ret.data.personCharData.forEach(ele => {
          // console.log(ele);
          arrs.types.push(ele.role)
          arrs.data.push(ele.total)
        });
        // console.log('chart3...');
        // console.log(arrs);

        this.$nextTick(() => {
          //   this.chart6(ret.data);
          this.indexPersonData = getPersonOption(arrs);
          this.loadingFlag = false;
        });
      });
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.init();
  },
  //生命周期-创建之前
  beforeCreated() {},
  //生命周期-挂载之前
  beforeMount() {},
  //生命周期-更新之前
  beforUpdate() {},
  //生命周期-更新之后
  updated() {},
  //生命周期-销毁之前
  beforeDestory() {},
  //生命周期-销毁完成
  destoryed() {},
  //如果页面有keep-alive缓存功能，这个函数会触发
  activated() {},
};
</script>
<style lang='less' scoped>
/* @import url(); 引入css类 */
.chart3 {
  width: 100%;
  height: 100%;
  position: relative;
  .e-loading {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
  }
}
</style>